package com.djx.elasticsearch.controller;

import com.djx.comm.controller.BaseController;
import com.djx.elasticsearch.entity.DocBean;
import com.djx.elasticsearch.service.DocBeanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @author PACTERA-468
 */
@RestController
@RequestMapping("/docBean")
public class DocBeanController extends BaseController {

    @Autowired
    DocBeanService docBeanService;

    @GetMapping("/init")
    public Object init(){
        docBeanService.createIndex();
        List<DocBean> list =new ArrayList<>();
        list.add(new DocBean(1L,"XX0193","XX8064","xxxxxx",1));
        list.add(new DocBean(2L,"XX0210","XX7475","xxxxxxxxxx",1));
        list.add(new DocBean(3L,"XX0257","XX8097","xxxxxxxxxxxxxxxxxx",1));
        docBeanService.saveAll(list);
        return successMsg("添加成功");
    }

    @GetMapping("/all")
    public Iterator<DocBean> all(){
        return docBeanService.findAll();
    }

    @GetMapping("/findByContent")
    public Page<DocBean> findByContent(String key){
        return docBeanService.findByContent(key);
    }
    @GetMapping("/findByFirstCode")
    public Page<DocBean> findByFirstCode(String key){
        return docBeanService.findByFirstCode(key);
    }
    @GetMapping("/findBySecordCode")
    public Page<DocBean> findBySecordCode(String key){
        return docBeanService.findBySecordCode(key);
    }
    @GetMapping("/query")
    public Page<DocBean> query(String key){
        return docBeanService.query(key);
    }

    @GetMapping("/getById")
    public DocBean getById(String id){
        return docBeanService.getById(id);
    }
}
